package model.room
{
	import core.Model;
	
	import events.ModelDataEvent;
	
	import flash.events.EventDispatcher;

	public class FriendModel extends EventDispatcher
	{
		private var datas:Array;
		private var _model:Model = Model.getInstance();
		
		public function FriendModel()
		{
		}
		
		public function updateDatas(datas:Array):void
		{
			this.datas = datas;
			var event:ModelDataEvent = new ModelDataEvent(ModelDataEvent.UPDATE);
			event.datas = datas;
			dispatchEvent(event);
		}
		
		public function sendDeleteFriend():void
		{
			if (datas == null)
			{
				return;
			}
			var outDatas:Array = [];
			for each (var data:FriendData in datas)
			{
				if (data.result == 1 && data.type == 1)
				{
					outDatas.push(data);
				}
			}
			
			if (outDatas.length == 0)
			{
				return;
			}
			
			_model.netRemote.sendRemoveFriend(outDatas);
		}
		
		public function clear():void
		{
			if (this.datas)
			{
				this.datas.length = 0;
				updateDatas(datas);
			}
			this.datas = null;
		}
	}
}